Namespace UI
    ''' <summary>
    ''' Defines a User control setting, this should cater for everything that implements the IStreamRecieve
    ''' </summary>
    ''' <remarks></remarks>
    <Serializable(), ObfuscationAttribute(Exclude:=True, ApplyToMembers:=True)> _
    Public Class UserStreamControlSettings

        Private mName As String = ""
        Private mItems As New KeyedStringCollectionWithEvents
        Private mDataRefreshTime As Integer = 0
        Private mData As Byte()

        Sub New(ByVal Name As String)
            mName = Name
        End Sub

        ''' <summary>
        ''' Specifies the Name of the control that this setting applies to!
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Name() As String
            Get
                Return mName
            End Get
        End Property

        ''' <summary>
        ''' Configures the stream item names for the config
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property StreamItems() As KeyedStringCollectionWithEvents
            Get
                Return mItems
            End Get
        End Property

        ''' <summary>
        ''' Applies the settings to the target control
        ''' </summary>
        ''' <param name="Control"></param>
        ''' <remarks></remarks>
        Public Sub ApplySettings(ByVal Control As DataStream.IStreamConfig)

            ' Apply the basic colection
            If Not Control.StreamControlItems Is Nothing Then
                Control.StreamControlItems.Clear()

                If mItems.Count > 0 AndAlso Not Control.StreamControlItems Is Nothing Then
                    For Each str As String In mItems
                        Control.StreamControlItems.Add(str)
                    Next
                End If
            End If

            ' Apply the stream control's data
            If Not mData Is Nothing Then
                Control.StreamControlData = mData
            End If

            ' Apply the data refresh time
            Control.DataRefreshTime = mDataRefreshTime
        End Sub

        ''' <summary>
        ''' Saves the setting from the target control
        ''' </summary>
        ''' <param name="Control"></param>
        ''' <remarks></remarks>
        Public Sub SaveSetting(ByVal Control As DataStream.IStreamConfig)
            ' Save the simple stuff
            Me.mItems.Clear()
            If Not Control.StreamControlItems Is Nothing AndAlso Control.StreamControlItems.Count > 0 Then
                For Each str As String In Control.StreamControlItems
                    Me.mItems.Add(str)
                Next
            End If

            ' Save the controls custom data
            mData = Control.StreamControlData

            ' Save the data refresh time
            mDataRefreshTime = Control.DataRefreshTime
        End Sub

    End Class
End Namespace


